const {
    wechatAPIS
} = require('../../tools/wechatApi');
const {
    Mysql,
    TripleEncrypt
} = require('./config');
module.exports = async ctx => {
    let {
        openId
    } = ctx.query;
    try {
        if (!openId) {
            ctx.state.data = {
                code: '002',
                msg: '参数确实'
            }
        } else {
            let sql = `SELECT user_info FROM userInfo WHERE open_id = '${openId}'`;
            let res = await Mysql(sql);
            let userInfo = await wechatAPIS.getBaseInfo(openId);
            let data = TripleEncrypt(JSON.stringify({
                ...JSON.parse(res),
                ...userInfo
            }))
            ctx.state.data = {
                code: '001',
                data
            }
        }
    } catch (error) {
        ctx.state.data = {
            code: '002',
            msg: '内部错误'
        }
    }
}